// pages/mine/mine.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        navBarHeight: app.globalData.navBarHeight,
        motto: 'Hello World',
        userInfo: {},
        hasUserInfo: false,
        canIUseGetUserProfile: false,
        canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), // 如需尝试获取用户信息可改为false
        funcArr: [
            { funcName: '观影记录', jumpPath: '/mineSubPackage/pages/viewingRecord/viewingRecord' },
            { funcName: '关注记录', jumpPath: '/mineSubPackage/pages/followRecord/followRecord' },
            { funcName: '客服热线', jumpPath: '' }
        ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (wx.getUserProfile) {
            this.setData({
                canIUseGetUserProfile: true
            })
        }
        const user = wx.getStorageSync('userInfo')
        if (user !== '') {
            this.setData({
                userInfo: wx.getStorageSync('userInfo') || {},
                hasUserInfo: true
            })
        }
    },
    getUserInfomation(e) {
        wx.getUserProfile({
            desc: '展示用户信息',
            success: (res) => {
                wx.setStorageSync('userInfo', res.userInfo)
                this.setData({
                    userInfo: res.userInfo,
                    hasUserInfo: true
                }, () => {
                    wx.hideLoading()
                })
            },
            complete: () => {
                wx.showLoading({
                    title: '登录中...',
                })
            }
        })
    },


    // 跳转页面
    jumpTo({ currentTarget }) {
        const user = wx.getStorageSync('userInfo')
        const { jumppath } = currentTarget.dataset
        user
            ? jumppath
                ? wx.navigateTo({
                    url: jumppath
                })
                : null
            : wx.showToast({
                title: '客官请先登录',
                icon: 'none'
            })
    }
})